<template>
    <div class="MusicManage">
        <div class="NavigationBar_mod">
            <el-menu default-active="3" class="el-menu-vertical-demo" :collapse="isCollapse" background-color="#545c64"
                text-color="#fff" active-text-color="#e58c43">
                <router-link to="/">
                    <el-menu-item index="1">
                        <el-icon>
                            <House />
                        </el-icon>
                        <template #title><span>首页</span></template>
                    </el-menu-item>
                </router-link>
                <router-link to="/songLibrary">
                    <el-menu-item index="2">
                        <el-icon>
                            <Headset />
                        </el-icon>
                        <template #title><span>歌曲库</span></template>
                    </el-menu-item>
                </router-link>
                <router-link to="/examine">
                    <el-menu-item index="3">
                        <el-icon>
                            <Coordinate />
                        </el-icon>
                        <template #title><span>歌曲审核</span></template>
                    </el-menu-item>
                </router-link>
            </el-menu>
        </div>
        <div class="content_mod">
            <el-affix>
                <div class="TopBar_mod">
                    <div class="logo_mod">
                        <div class="isCollapse_mod" @click="expand()">
                            <img src="../assets/photos/logo/展开.png" v-if="isCollapse">
                            <img src="../assets/photos/logo/收起.png" v-if="isCollapse === false">
                        </div>
                        <div class="SYIcon_mod">
                            <img src="../assets/photos/logo/AUT.png">
                        </div>
                    </div>
                    <div class="adminInfo_mod">
                        <label>{{ admin.admin_Name }}</label>
                        <div class="option_mod">
                            <el-col :span="8">
                                <el-dropdown trigger="click">
                                    <span class="el-dropdown-link"><el-icon>
                                            <CaretBottom />
                                        </el-icon></span>
                                    <template #dropdown>
                                        <el-dropdown-menu slot="dropdown">
                                            <router-link to="/" style="text-decoration: none;">
                                                <el-dropdown-item>首页</el-dropdown-item>
                                            </router-link>
                                            <el-dropdown-item>编辑资料</el-dropdown-item>
                                            <el-dropdown-item>切换用户</el-dropdown-item>
                                            <el-dropdown-item divided style="color: red"
                                                @click="exitLogin()">退出登录</el-dropdown-item>
                                        </el-dropdown-menu>
                                    </template>
                                </el-dropdown>
                            </el-col>
                        </div>
                    </div>
                </div>
            </el-affix>
            <div class="songLibrary_mod">
                <div class="songList_mod">
                    <div class="list_header">
                        <span>{{ defaultLibrary }}</span>
                        <el-dropdown trigger="click" @command="handleCommand">
                            <el-icon class="el-icon--right"><arrow-down /></el-icon>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-dropdown-item command=0>歌曲审核</el-dropdown-item>
                                    <el-dropdown-item command=1>歌曲上架</el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                    <div class="list_body">
                        <div class="list_title">
                            <span style="width: 50px;text-align: center;">#</span>
                            <span style="width: 400px;">名称</span>
                            <span style="width: 300px;">作者</span>
                            <span style="width: 300px;">时间</span>
                            <span style="width: 100px;"></span>
                        </div>
                        <div class="list_form" v-if="changeflag === 0">
                            <el-scrollbar height="602px">
                                <div class="songlist" v-for="(item, key) in AuditSonglists" @change="selectCollec(item.id)">
                                    <div style="width: 50px;text-align: center;">{{ key + 1 }}</div>
                                    <div style="width: 400px;">
                                        {{ item.song_Name }}
                                    </div>
                                    <div style="width: 300px;">{{ item.singer_ID }}</div>
                                    <div style="width: 300px;">{{ item.created_Time }}</div>
                                    <div style="width: 100px;">
                                        <el-popconfirm :title=item.song_Name confirm-button-text="确定"
                                            cancel-button-text="取消" icon-color="#f60101"
                                            @confirm="ApprovedSong(item.song_ID, item.song_Name)">
                                            <template #reference>
                                                <el-button type="warning" plain>通过</el-button>
                                            </template>
                                        </el-popconfirm>
                                    </div>
                                </div>
                            </el-scrollbar>
                        </div>
                        <div class="list_form" v-if="changeflag === 1">
                            <el-scrollbar height="602px">
                                <div class="songlist" v-for="(item, key) in banSongList" @change="selectCollec(item.id)">
                                    <div style="width: 50px;text-align: center;">{{ key + 1 }}</div>
                                    <div style="width: 400px;">
                                        {{ item.song_Name }}
                                    </div>
                                    <div style="width: 300px;">{{ item.singer_ID }}</div>
                                    <div style="width: 300px;">{{ item.created_Time }}</div>
                                    <div style="width: 100px;">
                                        <el-popconfirm :title=item.song_Name confirm-button-text="确定"
                                            cancel-button-text="取消" icon-color="#f60101"
                                            @confirm="arriveSong(item.song_ID, item.song_Name)">
                                            <template #reference>
                                                <el-button type="success" plain>上架</el-button>
                                            </template>
                                        </el-popconfirm>
                                    </div>
                                </div>
                            </el-scrollbar>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <el-backtop :bottom="100">
        <div style="
        height: 100%;
        width: 100%;
        background-color: var(--el-bg-color-overlay);
        box-shadow: var(--el-box-shadow-lighter);
        text-align: center;
        line-height: 40px;
        color: #e58c43;
                        ">
            <el-icon>
                <Top />
            </el-icon>
        </div>
    </el-backtop>
</template>
<style scoped src="../style/examine.css"></style>
<script>
export default {
    data() {
        return {
            isCollapse: true,
            changeflag: 0,
            defaultLibrary: '歌曲审核',
            admin: {
                admin_ID: '',
                admin_Name: '未登录',
            },
            onlineNum: 0,
            banSongList: [
                {
                    song_ID: '',
                    song_Name: '',
                    singer_ID: '',
                    created_Time: '',
                },
            ],
            AuditSonglists: [
                {
                    song_ID: '',
                    song_Name: '',
                    singer_ID: '',
                    created_Time: '',
                },
            ],
        }

    },
    mounted() {
        var admin_ID = window.sessionStorage.getItem('admin_ID');
        this.adminDetail("admin_ID")
        this.selectAllAuditSong()
        this.selectAllBanSong()
    },
    methods: {
        adminDetail(admin_ID) {
            let that = this;
            this.$axios({
                method: 'get',
                url: 'http://localhost:8080/admin/detailByAdminID?admin_ID=' + admin_ID,
            }).then(resp => {
                if (resp.data.code === 200) {
                    that.admin = resp.data.data
                }
                else {
                    console.log.resp.data.msg
                }

            })
        },
        selectAllAuditSong() {
            let that = this;
            this.$axios({
                method: 'get',
                url: 'http://localhost:8080/song/getUnapprovedSong'
            }).then(resp => {
                if (resp.data.code === 200) {
                    that.AuditSonglists = resp.data.data
                    console.log(resp.data.data)
                }
                else {
                    console.log(resp.data.msg)
                }

            })
        },
        selectAllBanSong() {
            let that = this;
            this.$axios({
                method: 'get',
                url: 'http://localhost:8080/song/getBanSong'
            }).then(resp => {
                if (resp.data.code === 200) {
                    that.banSongList = resp.data.data
                }
                else {
                    console.log(resp.data.msg)
                }

            })
        },
        ApprovedSong(song_ID, song_Name) {
            let that = this;
            this.$axios({
                method: 'get',
                url: 'http://localhost:8080/song/ApprovedSong?song_ID=' + song_ID,
            }).then(resp => {
                if (resp.data.code === 200) {
                    this.$message.success(song_Name + "审核通过！")
                    that.selectAllAuditSong()
                }
                else {
                    console.log(resp.data.msg)
                }

            })
        },
        arriveSong(song_ID, song_Name) {
            let that = this;
            this.$axios({
                method: 'get',
                url: 'http://localhost:8080/song/arriveSong?song_ID=' + song_ID,
            }).then(resp => {
                if (resp.data.code === 200) {
                    this.$message.success(song_Name + "上架成功！")
                    that.selectAllBanSong()
                }
                else {
                    console.log(resp.data.msg)
                }

            })
        },
        exitLogin() {
            router.push("/login")
            window.sessionStorage.setItem('admin_ID', null);
        },
        handleCommand(command) {
            if (command == 0) {
                this.defaultLibrary = '歌曲审核'
                this.changeflag = 0
            }
            else {
                this.defaultLibrary = '歌曲上架'
                this.changeflag = 1
            }
        },
    }

}
</script>